﻿
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.MeiTuanPeiSong.Model.Dto;
using SHKF.B2C.MeiTuanPeiSong.Network;
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks; 

namespace SHKF.B2C.MeiTuanPeiSong.Service.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class TestController : ControllerBase
    {
        private readonly HttpClientMeiTuanPeiSong httpClient;
        private readonly ILogger<TestController> logger;


        public TestController( HttpClientMeiTuanPeiSong httpClient, 
            ILogger<TestController> logger)
        {
            this.httpClient = httpClient;
            this.logger = logger;
        }

        [HttpGet("Get")]
        public string Get(string text)
        {
            this.logger.LogInformation($"/TestGet {DateTime.Now}");
            return "TestController" + text;
        }


        [HttpGet("shop/status/callback")]
        public async Task<string> ShopStatusCallback(string shop_id, int status)
        {
            CodeDto result = await this.httpClient.TestShopStatusCallback(shop_id, status);

            return "";
        }

        /// <summary>
        /// 模拟接单
        /// </summary>
        /// <returns></returns>
        [HttpGet("order/arrange")]
        [HttpPost("order/arrange")]
        public async Task<string> OrderArrange(long delivery_id, string mt_peisong_id)
        {
            try
            {  
                CodeDto result = await this.httpClient.TestOrderArrange(delivery_id, mt_peisong_id);


            }
            catch (Exception ex)
            {
                this.logger.LogWarning(ex.Message);
            }
            return "";
        }

        /// <summary>
        /// 模拟取货
        /// </summary>
        /// <param name="delivery_id"></param>
        /// <param name="mt_peisong_id"></param>
        /// <returns></returns>
        [HttpGet("order/pickup")]
        public async Task<string> OrderPickup(long delivery_id, string mt_peisong_id)
        {
            CodeDto result = await this.httpClient.TestOrderPickup(delivery_id, mt_peisong_id);

            return "";
        }


        /// <summary>
        /// 模拟送达
        /// </summary>
        /// <param name="delivery_id"></param>
        /// <param name="mt_peisong_id"></param>
        /// <returns></returns>
        [HttpGet("order/deliver")]
        public async Task<string> OrderDeliver(long delivery_id, string mt_peisong_id)
        {
            CodeDto result = await this.httpClient.TestOrderDeliver(delivery_id, mt_peisong_id);

            return "";
        }

        /// <summary>
        /// 模拟改派
        /// </summary>
        /// <param name="delivery_id"></param>
        /// <param name="mt_peisong_id"></param>
        /// <returns></returns>
        [HttpGet("order/rearrange")]
        public async Task<string> OrderRearrange(long delivery_id, string mt_peisong_id)
        {
            CodeDto result = await this.httpClient.TestOrderRearrange(delivery_id, mt_peisong_id);

            return "";
        }


        /// <summary>
        /// 模拟异常
        /// </summary>
        /// <param name="delivery_id"></param>
        /// <param name="mt_peisong_id"></param>
        /// <returns></returns>
        [HttpGet("order/reportException")]
        public async Task<string> OrderReportException(long delivery_id, string mt_peisong_id)
        {
            CodeDto result = await this.httpClient.TestOrderReportException(delivery_id, mt_peisong_id);

            return "";
        }

    }
}
